<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:demand:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:demand:edit']"
          >修改</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:demand:remove']"
            >删除</el-button
          >
        </el-col>-->

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" width="50" />
      <el-table-column
        label="供应商"
        align="center"
        prop="resourceSupply.createBy"
      />
      <el-table-column
        label="供应标题"
        align="center"
        prop="resourceSupply.supplyTitle"
      />
      <el-table-column
        label="申请单号"
        align="center"
        prop="resourceOrderNumber"
      />
      <el-table-column label="资源类型" align="center">
        <template #default="{ row }">
          {{
            row.resourceSupply.supplyType === 1
              ? "机柜"
              : row.resourceSupply.supplyType === 2
              ? "带宽"
                : row.resourceSupply.supplyType === 3
                  ? "算力服务器"
                  : row.resourceSupply.supplyType === 4
                    ? "算力"
              : "硬件"
          }}
        </template>
      </el-table-column>

      <el-table-column label="联系人" align="center" prop="contactUser" />
      <el-table-column
        label="联系方式"
        align="center"
        prop="contactUserMobile"
      />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="需求时间" align="center" width="240">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.supplyTime, "{y}-{m}-{d}") }}</span> ~
          <span>{{ parseTime(scope.row.orderLastTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template #default="{ row }">
          {{
            row.status === -1
              ? "已驳回"
              : row.status === 1
              ? "协商"
              : row.status === 2
              ? "批准"
              : row.status === 4
              ? "已取消"
              : "审核中"
          }}</template
        >
      </el-table-column>
      <el-table-column label="申请说明" align="center" prop="supplyDesc" />
      <el-table-column label="创建时间" prop="createTime" align="center" width="180" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button type="text" @click="doDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <DetailDrawer
      :visible.sync="showDrawer"
      :id="supplyId"
      :type="1"
    />
  </div>
</template>

<script>
import { listApply } from "@/api/system/apply";
import DetailDrawer from "@/views/review/components/detailDrawer.vue";

export default {
  name: "Demand",
  components: {DetailDrawer},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      showDrawer: false,
      // 供给信息id
      supplyId: null,
      // 总条数
      total: 0,
      // 需求信息表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listApply(this.queryParams).then((response) => {
        this.list = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    doDetail(row) {
      this.supplyId = row.supplyId;
      this.$nextTick(() => {
        this.showDrawer = true;
      });
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加需求信息";
    // },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const demandId = row.id || this.ids;
    //   getDemand(demandId).then((response) => {
    //     this.form = response.data;
    //     this.form.provinceArr = [
    //       response.data.provinceName,
    //       response.data.cityName,
    //     ];
    //     this.open = true;
    //     this.title = "修改需求信息";
    //   });
    // },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate((valid) => {
    //     if (valid) {
    //       this.form.provinceName = this.form.provinceArr[0];
    //       this.form.cityName = this.form.provinceArr[1];
    //       if (this.form.id != null) {
    //         updateDemand(this.form).then((response) => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addDemand(this.form).then((response) => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const demandIds = row.demandId || this.ids;
    //   this.$modal
    //     .confirm('是否确认删除需求信息编号为"' + demandIds + '"的数据项？')
    //     .then(function () {
    //       return delDemand(demandIds);
    //     })
    //     .then(() => {
    //       this.getList();
    //       this.$modal.msgSuccess("删除成功");
    //     })
    //     .catch(() => {});
    // },
    /** 导出按钮操作 */
    // handleExport() {
    //   this.download(
    //     "system/demand/export",
    //     {
    //       ...this.queryParams,
    //     },
    //     `demand_${new Date().getTime()}.xlsx`
    //   );
    // },
  },
};
</script>
